package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.ReqSearchClaTime;
import com.ruoyi.system.domain.ScClaTimeAttend;
import com.ruoyi.system.domain.SearchClaTime;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ScClaTime;
import com.ruoyi.system.service.IScClaTimeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 排课信息Controller
 * 
 * @author ruoyi
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/system/time")
public class ScClaTimeController extends BaseController
{
    @Autowired
    private IScClaTimeService scClaTimeService;

    /**
     * 查询排课信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:time:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScClaTimeAttend scClaTime)
    {
        startPage();
        List<ScClaTimeAttend> list = scClaTimeService.selectScClaTimeList(scClaTime);
        return getDataTable(list);
    }

    /**
     * 导出排课信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:time:export')")
    @Log(title = "排课信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScClaTime scClaTime)
    {
        List<ScClaTime> list = scClaTimeService.selectScClaTimeList(scClaTime);
        ExcelUtil<ScClaTime> util = new ExcelUtil<ScClaTime>(ScClaTime.class);
        util.exportExcel(response, list, "排课信息数据");
    }

    /**
     * 获取排课信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:time:query')")
    @GetMapping(value = "/{courseTimeId}")
    public AjaxResult getInfo(@PathVariable("courseTimeId") Long courseTimeId)
    {
        return AjaxResult.success(scClaTimeService.selectScClaTimeByCourseTimeId(courseTimeId));
    }

    /**
     * 新增排课信息
     */
    @PreAuthorize("@ss.hasPermi('system:time:add')")
    @Log(title = "排课信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScClaTime scClaTime)
    {
        return toAjax(scClaTimeService.insertScClaTime(scClaTime));
    }

    /**
     * 修改排课信息
     */
    @PreAuthorize("@ss.hasPermi('system:time:edit')")
    @Log(title = "排课信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScClaTime scClaTime)
    {
        return toAjax(scClaTimeService.updateScClaTime(scClaTime));
    }

    /**
     * 删除排课信息
     */
    @PreAuthorize("@ss.hasPermi('system:time:remove')")
    @Log(title = "排课信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{courseTimeIds}")
    public AjaxResult remove(@PathVariable Long[] courseTimeIds)
    {
        return toAjax(scClaTimeService.deleteScClaTimeByCourseTimeIds(courseTimeIds));
    }


    /**
     * 按周获取课表
     *
     * @param reqSearchClaTime
     * @return 周课表
     */
    @PostMapping ("/list/searchListForCalendar")
    public AjaxResult searchListForCalendar(@RequestBody  ReqSearchClaTime reqSearchClaTime) {
        return scClaTimeService.searchListForCalendar(reqSearchClaTime);
    }


    /**
     * 按请假时间获取个人课表
     *
     * @param form
     * @return 周课表
     */
    @PostMapping("/list/searchList")
    public AjaxResult searchListForCalendar(@RequestBody SearchClaTime form) {

        return scClaTimeService.searchListForLeave(form);
    }
    /**
     * 查找教师对应日期需要点名的课
     *
     */
    @PostMapping("/list/searchTeacherIdList")
    public AjaxResult searchListForTeacherId(@RequestBody ScClaTime scClaTime ) {
        return  AjaxResult.success(scClaTimeService.selectScClaTimeTeacherIdList(scClaTime));
    }

    /**
     * 查找教师对应日期需要点名的课
     *
     */
    @PostMapping("/list/selectScClaTimeClaIdList")
    public AjaxResult searchListForClaId(@RequestBody ScClaTime scClaTime ) {
        return  AjaxResult.success(scClaTimeService.selectScClaTimeClaIdList(scClaTime));
    }
}
